package lpl.com.xyd.test.manage.controller;

import com.alibaba.fastjson.JSONObject;
import lpl.com.xyd.test.manage.common.response.HttpResponse;
import lpl.com.xyd.test.manage.common.utils.ContentType;
import lpl.com.xyd.test.manage.facade.ProjectDemandsFacade;
import lpl.com.xyd.test.manage.form.ProjectDemandsAddForm;
import lpl.com.xyd.test.manage.form.ProjectDemandsQueryForm;
import lpl.com.xyd.test.manage.info.ProjectDemandsInfo;
import lpl.com.xyd.test.manage.order.ProjectDemandsAddOrder;
import lpl.com.xyd.test.manage.order.ProjectDemandsQueryOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/project/demands")
public class ProjectDemandsController {

    private final static Logger LOGGER = LoggerFactory.getLogger(ProjectDemandsController.class);

    @Autowired
    private ProjectDemandsFacade projectDemandsFacade;

    @RequestMapping(value = "/add",method = RequestMethod.POST,produces = {ContentType.APPLICATION_JSON_UTF_8,
            ContentType.TEXT_XML_UTF_8 })
    public HttpResponse<ProjectDemandsInfo> add(@RequestBody ProjectDemandsAddForm form){
        LOGGER.info("新增项目, form:{}", JSONObject.toJSONString(form));
        ProjectDemandsAddOrder order = new ProjectDemandsAddOrder();
        BeanUtils.copyProperties(form,order);
        return projectDemandsFacade.addProjectDemands(order);
    }

    @RequestMapping(value = "/query",method = RequestMethod.POST,produces = {ContentType.APPLICATION_JSON_UTF_8,
            ContentType.TEXT_XML_UTF_8 })
    public HttpResponse<List<ProjectDemandsInfo>> query(@RequestBody ProjectDemandsQueryForm form){
        LOGGER.info("查询项目测试需求, form:{}", JSONObject.toJSONString(form));
        ProjectDemandsQueryOrder order = new ProjectDemandsQueryOrder();
        BeanUtils.copyProperties(form,order);
        return projectDemandsFacade.query(order);
    }
}
